package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.demo.model.UserInfo;
import com.example.demo.service.UserService;

@Controller
@RequestMapping("/index")
public class indexController {
	@Autowired
	private UserService userservice;

	@GetMapping("/toIndex")
	public String toIndex() {
		return "../static/index2.html";
	}

	@GetMapping("/login")
	public String login() {
		return "/login";
	}

	@GetMapping("/login2")
	public String login2() {
		return "/login2";
	}

	@PostMapping("/login")
	public String toWelcome(UserInfo user) {
		if (null != user) {
			Boolean login = userservice.login(user);
			if (login) {
				return "/index";
			}
		}
		return "/404";
	}

	@PostMapping("/login2")
	public String toSuccess(UserInfo user) {
		if (null != user) {
			Boolean login = userservice.login(user);
			if (login) {
				return "/success";
			}
		}
		return "/404";
	}
}
